const debounce = (func, delay) => {
    let timer;
    return function (...args) {
        if(timer) {
        clearTimeout(timer);
        }
        timer = setTimeout(() => {
        func.apply(this, args);
        clearTimeout(timer);
        }, delay);
    };
};
export { debounce };

export const fetchTodos = params => {
    // console.log(params)
    let { query, tab, cityName, result} = params;
    // console.log(query, tab);
    console.log(result,'..')
    
    // result 存放获取赛事信息的数据
    if(tab) {
            switch(tab) {
                case "全部":
                    result = result.filter(todo => todo.pos.includes(cityName))
                    // 数组filter方法，过滤，筛选得到符合条件的信息
                    break;
                case "电竞赛事":
                    result = result.filter(todo => todo.type == '电竞赛事' && todo.pos.includes(cityName))
                    break;
                case "体育赛事":
                    result = result.filter(todo => todo.type == '体育赛事' && todo.pos.includes(cityName))

                default:
                    break;
            }
    }
    if(query) {
        result = result.filter(todo => todo.text.includes(query)||todo.pos.includes(query))
    }
    // Promise 类 resolve 静态方法
    // Promise.all 返回一个fullfiled 的 promise 实例
    return result
}